<%--
XPTracker - Alternative Agile Tracking Tool
Copyright (C) 2006-2009  Stephen Starkey

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
--%>
<%@ include file="/taglibs.jsp" %>
<%@ attribute name="story" type="org.xptracker.domain.Story" %>

<c:set var="story" value="${story}" scope="request"/>
<c:set var="storyId" value="${story.id}"/>
<c:set var="tasks" value="${story.tasks}"/>

<ul class="list-tasks" id="taskList">
  <jsp:include page="/display/taskList.jsp"/>
</ul>

<script type="text/javascript">
  function deleteTask(taskId) {
    if (confirm('Really delete this task?')) {
      document.deleteTask.taskId.value = taskId;
      sendForm({form: document.deleteTask, dest: 'taskList'});
    }
  }
</script>

<s:form id="deleteTask" beanclass="org.xptracker.web.TaskActionBean" name="deleteTask">
  <input type="hidden" name="Delete" value="1"/>
  <s:hidden id="taskId" name="id" value=""/>
</s:form>

<s:form id="reorderTasks" beanclass="org.xptracker.web.StoryActionBean" name="reorderTasks">
  <input type='hidden' name='ReorderTasks' value='1'/>  
  <s:hidden name="storyId" value="${storyId}"/>  
  <s:hidden name="taskOrder" value=""/>
</s:form>

<ss:secure roles="editor">
<s:url beanclass="org.xptracker.web.TaskActionBean" var="addTaskUrl"/>
<s:url beanclass="org.xptracker.web.DisplayActionBean" var="viewTaskUrl"/>
<script type="text/javascript">
  function showTaskWindow(taskId, edit) {
  	var url = (taskId && !edit) ? 
  		'${viewTaskUrl}?storyId=${storyId}&id=' + taskId :
  		'${addTaskUrl}?storyId=${storyId}' + (edit ? '&Edit=true' : '') + (taskId ? '&id=' + taskId : '') ;
  		
    var win = new Window('addTask_window', {className: 'alphacube', title: (edit ? "Edit" : "Add") + " Task", width:640, height:480,
                                            hideEffect:Element.hide, showEffect:Element.show, resizable: true, url: url});
    win.toFront();
    win.setDestroyOnClose();
    win.setConstraint(true, {left:0, right:0});
    win.showCenter();
  }
</script>

<script type="text/javascript">
  function toggleTask(checkbox, taskId) {
    document.setComplete.id.value = taskId;
    document.setComplete.complete.value = checkbox.checked;
    sendForm({form: document.setComplete,
              onComplete: function(response) {
                var newChecked = 'true' == response.responseText;
                if (newChecked) {
                  Element.addClassName('task_anchor_' + taskId, 'complete');
                } else {
                  Element.removeClassName('task_anchor_' + taskId, 'complete');
                }
              }});
  }
</script>

<s:form beanclass="org.xptracker.web.TaskActionBean" name="setComplete">
  <input type="hidden" name="complete" value="1"/>
  <input type="hidden" name="id"/>
  <input type="hidden" name="ToggleComplete"/>
  <s:hidden name="storyId" value="${storyId}"/>  
</s:form>

</ss:secure>
